/*
 * =====================================================================================
 *
 *       Filename:  led_on.c
 *
 *    Description:  点亮GPF4
 *
 *        Version:  1.0
 *        Created:  2018年10月29日 17时15分18秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */

/*
 * 为什么要用unsigned long，而不是unsigned int?
 */
#define GPFCON (*(volatile unsigned long*)0x56000050)
#define GPFDAT (*(volatile unsigned long*)0x56000054)

#define GPFCON_MASK(num) (3<<(num*2))
#define GPFCON_OUT(num)  (1<<(num*2))
#define GPFDAT_HIGH(num) (1<<num)


void delay(unsigned int time)
{
    while(time > 0) {
        time--;
    }
}

int main(int argc, char **argv)
{
    GPFCON &= ~(GPFCON_MASK(4));   /* GPIOF_4控制寄存器清零 */
    GPFCON |= GPFCON_OUT(4);       /* GPIOF_4控制寄存器设置为:输出模式 */
    GPFDAT |= GPFDAT_HIGH(4);      /* GPF4设置高电平 */
    GPFCON &= ~(GPFCON_MASK(5));   /* GPIOF_5控制寄存器清零 */
    GPFCON |= GPFCON_OUT(5);       /* GPIOF_5控制寄存器设置为:输出模式 */
    GPFDAT |= GPFDAT_HIGH(5);      /* GPF5设置高电平 */
    GPFCON &= ~(GPFCON_MASK(6));   /* GPIOF_6控制寄存器清零 */
    GPFCON |= GPFCON_OUT(6);       /* GPIOF_6控制寄存器设置为:输出模式 */
    GPFDAT |= GPFDAT_HIGH(6);      /* GPF6设置高电平 */
    while(1) {
        delay(30000); 
        GPFDAT &= ~GPFDAT_HIGH(4); /* GPF4设置低电平 */
        delay(30000); 
        GPFDAT &= ~GPFDAT_HIGH(5); /* GPF5设置低电平 */
        delay(30000); 
        GPFDAT &= ~GPFDAT_HIGH(6); /* GPF6设置低电平 */
        delay(30000); 
        GPFDAT |= GPFDAT_HIGH(4);  /* GPF4设置高电平 */
        delay(30000); 
        GPFDAT |= GPFDAT_HIGH(5);  /* GPF5设置高电平 */
        delay(30000); 
        GPFDAT |= GPFDAT_HIGH(6);  /* GPF6设置高电平 */
    }
    return 0;
}
